<?php
if(!$ajax):
?><div class="row">
	<div class="box col-md-12">
		<div class="box-inner">
			<div class="box-header well">
				<h2><i class="glyphicon glyphicon-user"></i> Danh sách hình ảnh</h2>
				<div class="box-icon">
					<a href="/mod/gallery/upload" class="btn btn-round btn-default"><i
                            class="glyphicon glyphicon-cog"></i></a>
					<a href="#" class="btn btn-minimize btn-round btn-default"><i class="glyphicon glyphicon-chevron-up"></i></a>
					<a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
				</div>
			</div>
			<div class="box-content">
				<div class="row" id="pagination_img"><?php
			else:
				?><div class="row" id="pagination_img"><?php
			endif;
					if(!empty($pagination)):
						foreach($pagination as $v):
							?><div class="col-xs-3">
								<a href="#" data-id="<?php echo $v->getId(); ?>" class="thumbnail" data-thumb="<?php echo site_url('/assets/upload/thumbs/'.html_escape($v->getName())); ?>" data-img="<?php echo site_url('/assets/upload/'.html_escape($v->getName())); ?>"><?php
									echo img(array(
										'src'=>site_url('/assets/upload/thumbs/'.html_escape($v->getName())),
										'style' => 'width:auto;height:120px',
										'alt' => html_escape($v->getName())
									));
								?></a>
							</div><?php
						endforeach;
					endif;
				?></div>
				<div class="row">
					<div class="col-xs-12"><?php
						echo $pagination_link;
					?></div>
				</div><?php
			if($ajax):
				?></div><?php
			else:
				?><div class="row">
					<div class="col-md-6 col-md-offset-3 form-horizontal">
						<div class="form-group">
							<label class="col-md-3 control-label" id="img_label">Hình ảnh</label><?php
							echo form_input(array(
								'name'=>'url','value'=>'','id'=>'img',
								'disabled'=>'disabled','class'=>'form-control'
							));
						?></div><div class="form-group">
							<label class="col-md-3 control-label" id="thumb_label">Hình đại diện</label><?php
							echo form_input(array(
								'name'=>'thumb','value'=>'','id'=>'thumb',
								'disabled'=>'disabled','class'=>'form-control'
							));
						?></div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div><?php
endif;
?><script>
url = '<?php echo base_url("/mod/gallery/"); ?>';
$('#img_label, #thumb_label').click(function(){
	$(this).parent().find('input').select();
});
$('#listSet').click(function(){
	$('#deleteForm').attr('action',url+'/listSet').submit();
});
$('#pagination_img a.thumbnail').selectable({
	filter:'a.thumbnail',
	stop:function(){
		var img  = $('#img').empty();

		$('.ui-selected').removeClass('ui-selected');
		$(this).addClass('ui-selected');
		$('#img').val($(this).attr('data-img')).select();
		$('#deleteForm input[name=img]').val($(this).find('img').attr('alt'));
		$('#thumb').val($(this).attr('data-thumb'));
		$('#deleteBtn').removeAttr('disabled');
		$('#listSet').removeAttr('disabled');
	}
})
</script>